package leetcode.dp;

import java.util.ArrayList;
import java.util.List;

public class Perm {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < 5; i++) {
            list.add(i);
        }
        process(list,0,5);
    }
    public static void process(List<Integer> list,int n,int m){
        if (n == m){
            for (int a:list) {
                System.out.print(a);
            }
            System.out.println();
        }else {
            for (int i = n; i < m; i++) {
                swap(list,i,n);
                process(list,n+1,m);
                swap(list,i,n);
            }
        }
    }

    public static void swap(List<Integer> list,int n,int m){
        int a = list.get(n);
        list.set(n,list.get(m));
        list.set(m,a);
    }
}
